/**
 * 
 */
package com.eagle.coders.core.action.delegates;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;

import com.eagle.coders.common.form.annotations.type.ActionTypes;
import com.eagle.coders.core.action.utils.BeanMapUtils;
import com.eagle.coders.core.action.vo.ActionResponseBean;

/**
 * @author Anees
 *
 */
public class ActionResponse {

	private Map<String, Object> resultObject = new HashMap<String, Object>();
	private Map<String, String> errors = new HashMap<String, String>();
	private ActionResponseBean actionResponseBeans;
	
	private ActionTypes actionType;
	
	private SortedMap<Integer, String> searchTableGeneratorMap;

	
	/**
	 * @return the resultObject
	 */
	public Map<String, Object> getResultObject() {
		return resultObject;
	}
	/**
	 * @param resultObject the resultObject to set
	 */
	public void setResultObject(Map<String, Object> resultObject) {
		this.resultObject = resultObject;
	}
	
	/**
	 * 
	 * @return
	 */
	public boolean hasErrors(){
		if(errors.size() > 0)
			return true;
		else
			return false;
	}

	/**
	 * @return the errors
	 */
	public Map<String, String> getErrors() {
		return errors;
	}
	/**
	 * @param errors the errors to set
	 */
	protected void setErrors(Map<String, String> errors) {
		this.errors = errors;
	}
	
	public void addError(String error, String message){
		errors.put(error, message);
	}
	
	/**
	 * @return the actionType
	 */
	public ActionTypes getActionType() {
		return actionType;
	}
	/**
	 * @param actionType the actionType to set
	 */
	public void setActionType(ActionTypes actionType) {
		this.actionType = actionType;
	}
	
	/**
	 * 
	 * @param objextList
	 */
	public void setResonseObjectList(List<? extends Object> objectList){
		System.out.println("[ActionResponse] : actionResponse :: "+objectList);
		ActionResponseBean actionResponseBean = new ActionResponseBean();
		for(Object obj : objectList){
			Map<String, Object> map = BeanMapUtils.bean2MapConverter(obj);
//			System.out.println("{ActionResponse] :: map :: "+map);
			actionResponseBean.setBeanValueMap(obj.getClass().getName(), map);
		}
		this.actionResponseBeans = actionResponseBean;
	}

	/**
	 * @return the actionResponseBean
	 */
	public ActionResponseBean getActionResponseBean() {
		return actionResponseBeans;
	}
	
	/**
	 * @return the searchTableGeneratorMap
	 */
	public SortedMap<Integer, String> getSearchTableGeneratorMap() {
		return searchTableGeneratorMap;
	}
	
	/**
	 * @param searchTableGeneratorMap the searchTableGeneratorMap to set
	 */
	public void setSearchTableGeneratorMap(
			SortedMap<Integer, String> searchTableGeneratorMap) {
		this.searchTableGeneratorMap = searchTableGeneratorMap;
	}
	
}